package com.example.iot.entity.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.example.iot.entity.EntityRelation;
import com.example.iot.entity.id.RuleNodeId;
import com.example.iot.mapper.mysql.handlers.UUIDTypeHandler;
import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.UUID;

/**
 * <p>
 * 
 * </p>
 *
 * @author ChenXiangpeng
 * @since 2021-02-25
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName(value = "relation", autoResultMap = true)
public class RelationPO implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.ASSIGN_UUID)
    private String uuid;

    /**
     * 连接关系发出节点
     */
    @TableField(typeHandler = UUIDTypeHandler.class)
    private UUID fromId;

    /**
     * 连接关系接收节点
     */
    @TableField(typeHandler = UUIDTypeHandler.class)
    private UUID toId;

    /**
     * 连接类型
     */
    private String relationType;

    /**
     * 连接关系
     */
    private String type;


    public static final String ID = "id";

    public static final String FROM_ID = "from_id";

    public static final String TO_ID = "to_id";

    public static final String RELATION_TYPE = "relation_type";

    public static final String TYPE = "type";

    public EntityRelation toDTO(){
        EntityRelation entityRelation = new EntityRelation();
        entityRelation.setFrom(new RuleNodeId(this.getFromId()));
        entityRelation.setTo(new RuleNodeId(this.getToId()));
        entityRelation.setType(this.getType());
        return entityRelation;
    }
}
